﻿using System;
using System.Collections.Generic;
using System.Text;
using com.gargoylesoftware.htmlunit;
using com.gargoylesoftware.htmlunit.html;

namespace WatiN.Core.HtmlUnit.Handlers
{
	public class HUWebWindowListener : WebWindowListener
	{

		public delegate void PageChangedDelegate(HtmlPage newPage, HtmlPage oldPage, string frame);
		public event PageChangedDelegate PageChanged;

		public HUWebWindowListener()
		{
			
		}

		#region WebWindowListener Members

		public void webWindowClosed(WebWindowEvent wwe)
		{
			
		}

		public void webWindowContentChanged(WebWindowEvent wwe)
		{
			WebWindow ww = wwe.getWebWindow();

			HtmlPage oldPage = (HtmlPage)wwe.getOldPage();
			HtmlPage newPage = (HtmlPage)wwe.getNewPage();

			if (PageChanged != null)
				PageChanged(newPage, oldPage, ww.getName());

			//Console.WriteLine("WWE: " + oldPage.getBaseURI() + " : " + newPage.getBaseURI());

		}

		public void webWindowOpened(WebWindowEvent wwe)
		{
			wwe.getNewPage();
		}

		#endregion
	}
}
